package com.cjq.orders.controller;

import com.cjq.orders.domain.Orders;
import com.cjq.orders.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 根据ID查询
     * @param ordersId
     * @return
     */
    @GetMapping("/findById")
    public Orders findById(Integer ordersId){
        Orders orders = ordersService.getById(ordersId);
        return orders;
    }

    /**
     * 列表
     * @return
     */
    @GetMapping("/ordersList")
    public List<Orders> ordersList(){
        List<Orders> ordersList = ordersService.list();
        return ordersList;
    }

    /**
     * 添加
     * @param orders
     */
    @PostMapping("/insert")
    public void insert(@RequestBody Orders orders){
        ordersService.save(orders);
    }

    /**
     * 修改
     * @param orders
     */
    @PutMapping("/update")
    public void update(@RequestBody Orders orders){
        ordersService.updateById(orders);
    }

    /**
     * 删除
     * @param ordersId
     */
    @DeleteMapping("/delete/{ordersId}")
    public void delete(@PathVariable Integer ordersId){
        ordersService.removeById(ordersId);
    }
}
